package com.cdcas;

import java.util.Arrays;

public class StudentTest {
    public static void main(String[] args) {
        String str = "SMITH:19:90.1|ALLEN:18:90.1|KING:20:95.2";
        String regex = "([a-zA-Z]+:\\d{1,3}:\\d{1,3}(\\.\\d{1,2})?\\|)+"
                + "([a-zA-Z]+:\\d{1,3}:\\d{1,3}(\\.\\d{1,2})?)?";
        if (str.matches(regex)) { 						// 符合于验证要求
            String result[] = str.split("\\|"); 		// 按正则拆分
            Student stu[] = new Student[result.length]; // 此时的数组大小就是对象数组大小
            for (int x = 0; x < result.length; x++) {
                String temp[] = result[x].split(":");
                stu[x] = new Student(temp[0], Integer.parseInt(temp[1]),
                        Double.parseDouble(temp[2]));
            }
            Arrays.sort(stu);							// 数组排序
            System.out.println(Arrays.toString(stu));
        } else {
            System.out.println("FLASE，输入非法！");
        }
    }
}
